//
//  HNCreditGoidLaoShi.m
//  XDEducation
//
//  Created by 星道 on 17/6/1.
//  Copyright © 2017年 apple. All rights reserved.
//

#import "HNCreditGoidLaoShi.h"
#import "HNCreditGoldController.h"
#import "HNCreditGoldSelectView.h"

@implementation HNCreditGoidLaoShi
{
    UIViewController *_VC;
}

- (instancetype)init_GetLaoShiInfoWithVC:(UIViewController *)VC
{
    self = [super init];
    if (self)
    {
        _VC = VC;
    }
    return self;
}








- (void)SelectRowWithTitle:(NSString *)Title
{
    
    if ([Title isEqualToString:@"学生"])
    {
        [self Student];
    }
    else if ([Title isEqualToString:@"自己"])
    {
        [self Own];
    }
    else
    {
        
    }
}



#pragma mark - 学生
- (void)Student
{
    //打开所有学生
    HNCreditGoldController *VC = [[HNCreditGoldController alloc] init];
    [self RefreshDataWithUrlStr:@"user.do?action=getAllStudent" Params:@{@"uid":[AccountTool shareAccountTool].currentAccount.uid} Complete:^(id responseObj) {
        NSMutableArray *Arr =[NSMutableArray array];
        NSMutableArray *Title_Arr = [NSMutableArray array];
        for (NSDictionary *Dict in responseObj)
        {
            NSString *PetName = @"";
            if ([Dict[@"nickName"] isEqualToString:@""])
            {
                PetName = [Dict[@"uid"] stringValue];
            }
            else
            {
                PetName = Dict[@"nickName"];
            }
            
            
            [Arr addObject:Dict];
            [Title_Arr addObject:PetName];
        }
        
        HNCreditGoldSelectView *SelectView = [[HNCreditGoldSelectView alloc] initWithTitle_Arr:Title_Arr SelectRow:^(NSString *Title) {
            
            //获取次级学生的数据后打开我的约定
            for (NSDictionary *Dict in Arr)
            {
                NSString *PetName = @"";
                if ([Dict[@"nickName"] isEqualToString:@""])
                {
                    PetName = [Dict[@"uid"] stringValue];
                }
                else
                {
                    PetName = Dict[@"nickName"];
                }
                if ([PetName isEqualToString:Title])
                {
                    [self RefreshDataWithUrlStr:@"user.do?action=getHonestValues" Params:@{@"uid":Dict[@"uid"]} Complete:^(id responseObj) {
                        
                        //爱心荣耀努力合约
                        VC.Love = responseObj[@"t"][@"redHearts"];
                        VC.Glory = responseObj[@"t"][@"stars"];
                        VC.Efforts = responseObj[@"t"][@"flowers"];
                        VC.Contract = responseObj[@"t"][@"honests"];
                        
                        [self RefreshDataWithUrlStr:@"user.do?action=getTargetStatus2" Params:@{@"supervisorUid":[AccountTool shareAccountTool].currentAccount.uid,@"executeUid":Dict[@"uid"]} Complete:^(id responseObj) {
                            
                            //小目标
                            VC.Small_NoFinish = responseObj[@"t"][@"notFinished"];
                            VC.Small_Finish = responseObj[@"t"][@"finished"];
                            
                            [self RefreshDataWithUrlStr:@"user.do?action=getBigTargetStatus2" Params:@{@"supervisorUid":[AccountTool shareAccountTool].currentAccount.uid,@"executeUid":Dict[@"uid"],@"uid":[AccountTool shareAccountTool].currentAccount.uid} Complete:^(id responseObj) {
                                
                                //大目标
                                VC.Big_NoFinish = responseObj[@"t"][@"notFinished"];
                                VC.Big_Finish = responseObj[@"t"][@"finished"];
                                VC.HNCreditGoldControllerAccoutType = HNCreditGoldControllerAccoutTypeXueSheng;
                                VC.uid = [Dict[@"uid"] stringValue];
                                [_VC.navigationController pushViewController:VC animated:YES];
                            }];
                        }];
                    }];
                    break;
                }
            }
        }];
        [[UIApplication sharedApplication].keyWindow.rootViewController.view addSubview:SelectView];
    }];
}

#pragma mark - 自己
- (void)Own
{
    HNCreditGoldController *VC = [[HNCreditGoldController alloc] init];
    [self RefreshDataWithUrlStr:@"user.do?action=getHonestValues" Params:@{@"uid":[AccountTool shareAccountTool].currentAccount.uid} Complete:^(id responseObj) {
        
        //爱心荣耀努力合约
        VC.Image = [AccountTool shareAccountTool].currentAccount.avatar;
        VC.Love = responseObj[@"t"][@"redHearts"];
        VC.Glory = responseObj[@"t"][@"stars"];
        VC.Efforts = responseObj[@"t"][@"flowers"];
        VC.Contract = responseObj[@"t"][@"honests"];
        
        [self RefreshDataWithUrlStr:@"user.do?action=getTargetStatus2" Params:@{@"supervisorUid":[AccountTool shareAccountTool].currentAccount.uid} Complete:^(id responseObj) {
            
            //小目标
            VC.Small_NoFinish = responseObj[@"t"][@"notFinished"];
            VC.Small_Finish = responseObj[@"t"][@"finished"];
            
            [self RefreshDataWithUrlStr:@"user.do?action=getBigTargetStatus2" Params:@{@"uid":[AccountTool shareAccountTool].currentAccount.uid} Complete:^(id responseObj) {
                
                //大目标
                VC.Big_NoFinish = responseObj[@"t"][@"notFinished"];
                VC.Big_Finish = responseObj[@"t"][@"finished"];
                VC.HNCreditGoldControllerAccoutType = HNCreditGoldControllerAccoutTypeZiJi;
                VC.uid = [AccountTool shareAccountTool].currentAccount.uid;
                [_VC.navigationController pushViewController:VC animated:YES];
            }];
        }];
    }];


}







+ (NSArray *)GetLaoShiInfo
{
    return @[@"学生",@"自己"];
}

- (void)RefreshDataWithUrlStr:(NSString *)UrlStr Params:(NSDictionary *)Params Complete:(void(^)(id responseObj))Complete
{
    [MBProgressHUD showHUD];
    [XDHttpTool get:BaseURL(UrlStr) authCode:[AccountTool shareAccountTool].currentAccount.authCode params:Params success:^(id responseObj) {
        
        
        Complete (responseObj);
        
    } failure:^(NSError *error) {
        [MBProgressHUD showError:XDNetWorkError];
    }];
}

@end
